<template>
  <div style="">
    <Header :left="true" leftText="返回" title="返工通知单"> </Header>
    <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
      left-icon="description">返工基本信息</NoticeBar>
    <van-form :style="autoHeight">

      <van-field readonly class="formstyle" name="text" :value="valueQualityAbnormalNotice.cans2" label="待返工清单"
        placeholder="点击选择待返工清单" @click="cans2" />
      <van-field v-model="form.OrderMemo" size="small" class="formstyle" center colon label="返工单描述"
        placeholder="请输入返工单描述" />

      <van-field readonly class="formstyle" name="picker" :value="valuepline" label="生产线" placeholder="点击选择产线" />
      <van-popup v-model="showPickerpline" position="bottom">
        <van-picker show-toolbar :columns="columnspline" @confirm="onConfirmpline" @cancel="showPickerpline = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.plineName }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>

      <van-field class="formstyle" v-model="form.POrderID" name="生产订单" label="生产订单" placeholder="生产订单"
        @click.stop="getProductionOrder" />
      <!-- <Icon slot="right-icon" center name="enlarge" size="2em"></Icon> -->



      <van-field v-model="form.MaterialID" size="small" class="formstyle" center colon label="产品代码" :readonly="true"
        placeholder="请先扫描订单条码" />

      <van-field v-model="form.MaterialName" size="small" class="formstyle" center colon label="产品名称" :readonly="true"
        placeholder="请先扫描订单条码" />


      <van-field readonly class="formstyle" name="picker" v-model="valueteamName" label="班组" placeholder="点击选择班组" />


      <van-field readonly v-model="form.BatchID" size="small" class="formstyle" center colon label="生产批次"
        placeholder="请输入生产批次" />


      <van-field :readonly="true" v-model="CreateDatetimeP" size="small" class="formstyle" center colon label="生产日期"
        placeholder="请输入申请生产日期选择" />

      <!-- <van-field readonly v-model="valuepShiftName" required size="small" class="formstyle" center colon label="班次"
        placeholder="请输入班次"  @click="showPickerpShiftID = true"/>
        <van-popup v-model="showPickerpShiftID" position="bottom">
        <van-picker
          show-toolbar
          :columns="columnsshift"
          @confirm="onConfirmpShiftID"
          @cancel="showPickerpShiftID = false"
        >
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center;">
              <div>{{ option.pshiftname }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup> -->
      <van-field v-model="form.DealWithAmount" required size="small" class="formstyle" center colon label="问题产品待处理数量"
        placeholder="问题产品待处理数量" />
      <van-field v-model="form.SampleAmount" required size="small" class="formstyle" center colon label="抽样数量"
        placeholder="请输入抽样数量" />

      <van-field v-model="user.employeeName" readonly required size="small" class="formstyle" center colon label="QC"
        placeholder="请输入QC" />
      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">缺陷类型</NoticeBar>
      <van-field style="font-weight: bold;border:1px solid #ccc!important;width: 95%;margin: 0 auto;"
        v-model="form.ReworkReason" class="formstyle" rows="4" autosize label="" type="textarea" maxlength="150"
        placeholder="" show-word-limit />
      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">返工方案</NoticeBar>
      <van-field required :readonly="true" size="small" class="formstyle" center colon :value="form.Operation"
        label="返工方案" placeholder="请输入返工方案" @click="showPickerpline1 = true" />
      <van-popup v-model="showPickerpline1" position="bottom">
        <van-picker show-toolbar :columns="columnspline1" @confirm="onConfirmpline1" @cancel="showPickerpline1 = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.plineName }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>
      <van-field v-model="form.ReworkAoumt" required size="small" class="formstyle" center colon label="返工数量"
        placeholder="请输入返工数量" />
      <NoticeBar color="#4e4a67" background="#ffffff" style="margin-top: 5px; font-size: 15px; font-weight: bold">方案说明：
      </NoticeBar>
      <van-field style="font-weight: bold;border:1px solid #ccc!important;width: 95%;margin: 0 auto;"
        v-model="form.OperationTxt" class="formstyle" rows="4" autosize label="" type="textarea" maxlength="150"
        placeholder="" show-word-limit />
      <van-row gutter="20">
        <van-col span="12">
          <div style="margin: 16px">
            <van-button color="#008792" round block type="info" @click="getRecord(form.AppearanceCheckRecord1)"
              style="">查看外观检验不合格记录</van-button>
          </div>
        </van-col>
        <van-col span="12">
          <div style="margin: 16px">
            <van-button color="#33a3dc" round block type="info" @click="checkSYS">查看实验室检验不合格项</van-button>
          </div>
        </van-col>
      </van-row>

      <van-row gutter="20">
        <van-col span="12">
          <div style="margin: 16px">
            <van-button color="#1AB394" round block type="info" @click="openQA">打开质量辅助决策界面</van-button>
          </div>
        </van-col>
        <van-col span="12">
          <div style="margin: 16px">
            <van-button color="#005831" round block type="info" @click="CheckTM">查看实验室复测记录</van-button>
          </div>
        </van-col>
      </van-row>
      <!-- <div style="margin: 16px">
        <van-button color="#23C6C8" round block type="info" @click="getRecord">查看外观检验不合格记录</van-button>
      </div>
      <div style="margin: 16px">
        <van-button color="#23C6C8" round block type="info" @click="checkSYS">查看实验室检验不合格项</van-button>
      </div>
      <div style="margin: 16px">
        <van-button color="#23C6C8" round block type="info" @click="openQA">打开质量辅助决策界面</van-button>
      </div>-->

      
      <div style="margin: 16px">
        <van-button round color="#138087" block type="info" @click="onSubmit">确认返工</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import {
  Col,
  Row,
  Form,
  Cell,
  Icon,
  Field,
  NumberKeyboard,
  Image as VanImage,
  Picker,
  popup,
  SubmitBar,
  Button,
  Loading,
  Overlay,
  Dialog,
  Toast,
  NoticeBar,
  Tag,
  DatetimePicker,
  ImagePreview,
  CellGroup,
  Uploader,
  Cascader,
  Calendar,
  RadioGroup,
  Radio,
  Divider,
  Stepper,
  AddressList,
  Checkbox,
  CheckboxGroup,
  Slider,
} from "vant";

import "vue-easytable/libs/themes-base/index.css";
import { VTable } from "vue-easytable";
import { _httpClient as _httpClientApisie } from "@/libs/apisie";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { getToken, getBaseApiFrefix } from "@/libs/auth";
import Header from "@/components/header.vue";
import { storage } from "@/libs/utils";

Vue.use(Form);
Vue.use(Field);
Vue.use(Overlay);
Vue.use(Loading);
Vue.use(Picker);
Vue.use(popup);
Vue.use(SubmitBar);
Vue.use(VanImage);
Vue.use(DatetimePicker);
Vue.use(Cascader);
Vue.use(Calendar);
Vue.use(Cell);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Divider);
Vue.use(Stepper);
Vue.use(Button);
Vue.use(AddressList);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Col);
Vue.use(Row);

export default {
  name: "rework",
  components: {
    Form,
    Row,
    Col,
    Button,
    Header,
    Form,
    Cell,
    Icon,
    Field,
    NumberKeyboard,
    Dialog,
    Toast,
    NoticeBar,
    Row,
    Tag,
    popup,
    DatetimePicker,
    ImagePreview,
    CellGroup,
    Uploader,
    Col,
    Calendar,
    Cascader,
    Picker,
    RadioGroup,
    Radio,
    Divider,
    Stepper,
    VTable,
    AddressList,
    Checkbox,
    CheckboxGroup,
  },
  data() {
    return {
      valuepShiftName: null,
      nowDate: null,
      CreateDatetimeP: null,
      form: {
        MaterialID: "",
        MaterialName: "",
        POrderID: "",
        Id: 0,
        PLineID: "",
        PShiftID: "",
        TeamID: "",
        OrderMemo: "",
        DefectAmount: 0,
        ProductionDate: "",
        AbnormalNoticeID: 0,
        SampleAmount: "0",
        ReworkAoumt: "",
        ReworkReason: "",
        BatchID: "",
        Operation: "",
        OperationTxt: "",
        lab: "",
        CheckItem: "",
        CheckBatch: ""
      },
      showPickermaterial: false,
      showdate: false,
      valuedatetime: "",
      showPickerpline1: false,
      showPickerdatetime: false,
      showPickerpline: false,
      valuepline: "",
      columnspline: [],
      columnspline1: [
        { plineId: "返修", plineName: "返修" },
        { plineId: "挑选", plineName: "挑选" },
        { plineId: "其他", plineName: "其他" },
      ],
      valuepShiftName: "",
      columnsshift: [],
      showPickerpShiftID: false,
      valueteamName: "",
      columnsteamId: [
        { teamId: "SJT01", teamName: "太仓塑胶A班" },
        { teamId: "SJT02", teamName: "太仓塑胶B班" },
      ],
      showPickerteamId: false,
      columnsQualityAbnormalNotice: [],
      valueQualityAbnormalNotice: {
        cans1: "点击页面操作",
        cans2: "点击页面操作"
      },
      showPickerQualityAbnormalNotice: false,

      columnsQualityDefectReview: [],
      //valueQualityDefectReview: "123",
      showPickerQualityDefectReview: false,
    };
  },
  watch: {

    "form.ReworkReason": {
      // immediate: true, 
      handler: function (newV, oldV) {
        // alert(newV)
        this.form.OrderMemo = this.form.POrderID + "-" + this.form.BatchID + "-" + this.CreateDatetimeP
        //this.form.OrderMemo = this.form.POrderID + "-" + this.form.BatchID + "-" + newV + "-" + new Date().toLocaleTimeString()
      },
    },
  },

  created: function () {

    this.user = JSON.parse(storage.get("user"));
    // alert(JSON.stringify(this.user))
    this.getFactoryID().then((response) => {
      this.getPline();
    });
    this.getQualityAbnormalNotice();
    this.getQualityDefectReview();
    this.refush();

  },
  mounted() {
    this.getNowTimeToSecond(); //进入页面调用该方法获取当前时间
    clearInterval(myTimeDisplay); //销毁之前定时器
    var myTimeDisplay = setInterval(() => {
      this.getNowTimeToSecond(); //每秒更新一次时间
    }, 1000);
    this.initPage();
  },

  destroyed() {
    clearInterval(this.nowtimer);
    this.nowDate = null;
  },

  methods: {

    async getRecord() {
      let _this = this;
      //alert(_this.form.qualityDefectReviewID);
      if (_this.form.qualityDefectReviewID == "") {
        alert("无外观检测不合格记录");
        return;
      }
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/QualityDefectReview/GetEntity?id=" + _this.form.qualityDefectReviewID
        );
        var item = res.Data;
        //alert(JSON.stringify(item));
        //alert(item.AppearanceCheckRecord);
        api.openWin({
          name: 'qCcheckReview',
          url: './quality-qCcheckReview.html',
          pageParam: {
            id: item.AppearanceCheckRecord
          }
        });
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    openQA() {
      let _this = this
      api.openWin({
        name: 'qAssistance',
        url: './qAssistance-qualityAssistance.html',
        pageParam: {
          POrderID: _this.form.POrderID,
          PlineID: _this.form.PLineID
        }
      });


    },
    getNowTimeplus() {
      let dateTime
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
        :
        new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
        :
        new Date().getSeconds()
      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      return dateTime
    },
    async CheckTM() {
      let id = this.lab;
      let CheckItem = this.form.CheckItem;
      let CheckBatch = this.form.CheckBatch;
      if (CheckBatch =="全项检验") {
        CheckBatch = "问题产品复核检验-全项"
      }
      else {
        CheckBatch = "问题产品复核检验-过程"
      }

      if (id == "" || id == null || id == undefined) {
        Toast.clear()
        Toast.fail("当前没有维护实验室复测记录，无法获取复测记录！")
        return
      }

      api.openWin({
        name: 'viewlaboratorytest1',
        url: './equipmentsj-viewlaboratorytest1.html',
        pageParam: {
          id: id,
          CheckBatch: CheckBatch,
          CheckItem: this.form.CheckItem
        }
      });
    },
    async checkSYS() {

      // let id = this.lab;

      // if (id == "") {
      //   Toast.clear()
      //   Toast.fail("请先选择返工通知单")
      //   return
      // }
      // if (id == "" || id == null || id == undefined) {
      //   Toast.clear()
      //   Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
      //   return
      // }
      // api.openWin({
      //   name: 'viewlaboratorytest',
      //   url: './equipmentsj-viewlaboratorytest.html',
      //   pageParam: {
      //     id: id
      //   }
      // });

      let id = this.lab;
      let CheckBatch = this.form.CheckBatch;
      let CheckItem = this.form.CheckItem;

      if (id == "" || id == null || id == undefined) {
        Toast.clear()
        Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
        return
      }

      api.openWin({
        name: 'viewlaboratorytest',
        url: './equipmentsj-viewlaboratorytest.html',
        pageParam: {
          id: id,
          CheckBatch: this.form.CheckBatch,
          CheckItem: this.form.CheckItem
        }
      });


      // let id=this.lab

      // if(id==""){
      //   Toast.clear()
      //   Toast.fail("请先选择返工通知单")
      //   return
      // }
      // if(id==""||id==null || id==undefined){
      //   Toast.clear()
      //   Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
      //   return
      // }


      // try {
      //   let res = await _httpClientApisie.get(
      //     _httpClientApisie.getApiPrefix() +
      //     "/QualityCheckRecord/GetQualityCheckDisqualifiedMsg?CheckRecordID="+id
      //   );
      //   if (res.HttpCode === "200") {
      //     alert(res.Data)
      //   }
      // } catch (e) {
      //   Toast.fail(JSON.stringify(e));
      // }
    },
    refush() {

      let that = this;

      api.addEventListener({
        name: 'cans2'
      }, function (ret, err) {
        that.form.qualityDefectReviewID = ret.value.cans2;
        that.lab = ret.value.lab;
        //alert(that.form.qualityDefectReviewID);
        that.getAbnMessage()
        that.form.SampleAmount = ret.value.sampleAmount
      });

      //this.valueQualityAbnormalNotice.cans1 = values;
      // alert(123);
      // alert(data);
      // this.valueQualityAbnormalNotice.cans1 = data;
    },
    async getAbnMessage() {

      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/QualityDefectReview/GetEntity?id=" + this.form.qualityDefectReviewID
        )

        this.valuepline = res.Data.PLineID;
        this.form.PLineID = res.Data.PLineID
        this.form.POrderID = res.Data.POrderID;
        this.form.MaterialID = res.Data.MaterialID;
        this.form.MaterialName = res.Data.MaterialName;
        this.form.TeamID = res.Data.TeamID;
        this.form.BatchID = res.Data.BatchID;
        this.CreateDatetimeP = res.Data.CreateDatetime




        this.form.ReworkReason = res.Data.QProblemID + res.Data.ManageReasonID + res.Data.FunctionProblemID + res.Data.DefectMemo
        this.form.CheckBatch = res.Data.CheckBatch;
        this.form.CheckItem = res.Data.CheckItem;
        this.form.DealWithAmount = res.Data.DeFectAmount
        this.form.OrderMemo = this.form.POrderID + "-" + this.form.BatchID + "-" + this.form.ReworkReason + "-" + new Date().toLocaleTimeString()
        let res2 = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/Team/GetList?TeamID=" + res.Data.TeamID
        )

        this.valueteamName = res2.Data[0].TeamName;
        // alert(JSON.stringify(res))
      } catch (e) {
        alert(JSON.stringify(e))
      }



    },
    //问题产品处理跟踪单号
    cans2() {
      api.openWin({
        name: "adjustmentdetailsitem",
        url: "./equipmentsj-adjustmentdetailsitem.html",
        reload: true,
      });
    },
    async sendmessage() {
      try {
        let _this = this;

        let eventDescription = "";
        let eventDatetime = _this.getNowTimeplus();
        let eventTypeID = "N3";
        let eventID = "";
        let messageContent = "";
        let msgContentTypeID = "";
        let pLineID = _this.form.PLineID;
        let machineID = _this.form.PLineID;
        let pShiftID = "";
        let teamID = "";
        let pOrderID = _this.form.POrderID;
        let productionBarcode = "";
        let materialBarcode = "";
        let relatedEmployee = "";
        let messageStatus = "";
        let processBatchID = "";
        let beginDatetime = _this.getNowTimeplus();
        let sendFinished = false;
        let closed = false;

        msgContentTypeID = "RW001";
        eventID = "RWK01";
        eventDescription = "生产返工单:" + _this.getNowTimeplus() + "已经被:" + this.user.employeeName + "创建，请按照返工要求及时进行返工处理！";
        messageContent = "生产订单" + _this.form.POrderID + "在生产线:" + _this.form.PLineID + "上生产时发生质量问题需要进行返工，返工原因是:" + _this.form.ReworkReason + ".请尽快组织人员进行返工处理！";


        let bodysss = {
          eventDescription: eventDescription,
          eventDatetime: eventDatetime,
          eventTypeID: eventTypeID,
          eventID: eventID,
          messageContent: messageContent,
          msgContentTypeID: msgContentTypeID,
          factoryID: "TC00",
          pLineID: pLineID,
          machineID: machineID,
          pShiftID: pShiftID,
          teamID: teamID,
          pOrderID: pOrderID,
          productionBarcode: productionBarcode,
          materialBarcode: materialBarcode,
          relatedEmployee: relatedEmployee,
          messageStatus: messageStatus,
          processBatchID: processBatchID,
          beginDatetime: beginDatetime,
          sendFinished: sendFinished,
          closed: closed
        };
        try {
          let res = await _httpClientApisie.post(
            _httpClientApisie.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
            {
              body: bodysss,
            }
          );
          //alert(JSON.stringify(res));
          if (res.Message == null) {
            Toast.clear();
            Toast.success("发送成功");
            setTimeout(function () {
              _this.$ac.closeWin();
            }, 2000);

          } else {
            Toast.clear();
            Toast.fail("发送失败");
          }
        } catch (e) {
          Toast.fail(JSON.stringify(e));
        }
      } catch (error) {
        alert(error);
      }
    },
    //确认返工
    async onSubmit() {

      var _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "请稍等...",
      });
      var bodyss = {
        POrderID: _this.form.POrderID,
        MaterialID: _this.form.MaterialID,
        MaterialName: _this.form.MaterialName,
        PLineID: _this.form.PLineID,
        PShiftID: "BC01",
        TeamID: _this.form.TeamID,
        OrderMemo: _this.form.OrderMemo,
        ProductionDate: _this.nowDate,
        SampleAmount: _this.form.SampleAmount,
        ReworkAoumt: _this.form.ReworkAoumt,
        ReworkReason: _this.form.ReworkReason,
        BatchID: _this.form.BatchID,
        FactoryID: "TC00",
        GoodAmount: 0,
        BadAmount: 0,
        QCLeader: _this.user.userName,
        DealWithAmount: _this.form.DealWithAmount,
        QualityDefectReviewID: _this.form.qualityDefectReviewID,
        Operation: _this.form.Operation,
        Creator: _this.user.userName,
        OperationTxt: _this.form.OperationTxt,
        CreateDatetime: new Date(),
        CompleteFlag: false,
        Comfirmed: false
      };
      try {
        let res = await _httpClientApisie.post(
          _httpClientApisie.getApiPrefix() + "/ReworkOrder/SaveEntity",
          {
            body: bodyss,
          }
        );
        if (res.Message != null) {
          //message不为空,有报错信息，打卡失败 暂时这样判断
          Toast.clear();
          Toast.fail("保存失败,请核对信息！" + res.Message);
        } else {
          //打卡成功
          Toast.clear();
          Toast.success("保存成功！");
          //修改标志位
          // alert(JSON.stringify(res))

          let res2 = await _httpClientApisie.post(
            _httpClientApisie.getApiPrefix() + "/QualityDefectReview/SaveEntity",
            {
              body: {
                Id: bodyss.QualityDefectReviewID,
                ReworkOrderCreated: true,
                ReworkOrderID: res.Data
              },
            }
          );

          // alert(JSON.stringify(res2))

          _this.sendmessage();
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    onConfirmpline1(value, index) {
      this.form.Operation = this.columnspline1[index].plineId;
      this.showPickerpline1 = false;
    },
    onConfirmteamId(value, index) {
      this.form.TeamID = this.columnsteamId[index].teamId;
      this.valueteamName = this.columnsteamId[index].teamName;
      this.showPickerteamId = false;
    },
    onConfirmpShiftID(value, index) {
      this.valuepShiftName = this.columnsshift[index].pshiftname;
      this.form.PShiftID = this.columnsshift[index].pShiftID;
      this.showPickerpShiftID = false;
    },
    onConfirmpQualityAbnormalNotice(value, index) {
      this.valueQualityAbnormalNotice =
        this.columnsQualityAbnormalNotice[index].NoticeMemoAndMaterialName;
      this.form.AbnormalNoticeID =
        this.columnsQualityAbnormalNotice[index].QualityAppearanceCheckId;
      this.showPickerQualityAbnormalNotice = false;
    },
    onConfirmQualityDefectReview(value, index) {
      this.valueQualityDefectReview =
        this.columnsQualityDefectReview[index].POrderIDAndMaterialName;
      this.form.QualityDefectReviewID =
        this.columnsQualityDefectReview[index].QualityDefectReviewId;
      this.showPickerQualityDefectReview = false;
    },
    //打开扫描
    showScanner() {
      let _this = this;
      if (
        api.deviceName.toLowerCase() == "huawei" ||
        api.deviceName.toLowerCase() == "honor"
      ) {

        var zyHmsScan = api.require('zyHmsScan');
        var param = {
          //returnAll:true
        };
        zyHmsScan.openDefaultView(param, function (ret) {
          // _this.addBarCode(ret.result);
          let arr = ret.result.split("_");
          _this.form.POrderID = arr[1];
          _this.getProductionOrder(_this.form.POrderID);
          //api.alert({ msg: JSON.stringify(ret) });
        });
      } else {
        var FNScanner = this.$ac.require("FNScanner");
        FNScanner.openScanner(
          {
            autorotation: true,
          },
          function (ret, err) {
            if (ret) {
              if (ret.eventType == "success" && ret.content != "") {
                let arr = ret.content.split("_");
                _this.form.POrderID = arr[1];
                _this.getProductionOrder(_this.form.POrderID);
              }
            } else {
              alert(JSON.stringify(err));
            }
          }
        );
      }
    },
    onConfirm(date) {
      this.showdate = false;
      this.form.ProductionDate = this.getNowTime(date);
    },
    // 获取当前时间 yy-mm-dd hh:mf:ss
    getNowTimeToSecond() {
      let dateTime;
      let dateTime1;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
      dateTime1 = yy + "-" + mm + "-" + dd;
      this.nowDate = dateTime1;
      return dateTime;
    },
    // 获取当前时间 yy-mm-dd
    getNowTime(date) {
      let yy = date.getFullYear();
      let mm = date.getMonth() + 1;
      let dd = date.getDate();
      return yy + "-" + mm + "-" + dd;
    },
    onConfirmpline(value, index) {
      this.valuepline = value;
      this.form.PLineID = this.columnspline[index].plineId;
      this.valuepline = this.columnspline[index].plineName;
      this.showPickerpline = false;
    },
    //获取工厂信息
    async getFactoryID() {
      let _this = this;
      try {
        let res = await _httpClientApi.get(
          _httpClientApi.getApiPrefix() +
          "/system/ConvertFactoryID/getList/" +
          _this.user.site
        );
        if (res.code === 200) {
          _this.user.site = res.data.sapfactoryid;
          _this.getshift(_this.user.site);
          _this.getteam(_this.user.site);
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取调机申请信息
    async getQualityAbnormalNotice() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/QualityAbnormalNotice/GetList"
        );
        if (res.HttpCode === "200") {
          let QualityAbnormalNoticeMap = res.Data.map((item) => ({
            QualityAppearanceCheckId: item.Id,
            NoticeMemoAndMaterialName:
              item.NoticeMemo + " " + item.MaterialName,
          }));
          _this.columnsQualityAbnormalNotice = QualityAbnormalNoticeMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取问题产品处置申请信息
    async getQualityDefectReview() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/QualityDefectReview/GetList"
        );
        if (res.HttpCode === "200") {
          let QualityDefectReviewMap = res.Data.map((item) => ({
            QualityDefectReviewId: item.Id,
            POrderIDAndMaterialName: item.POrderID + " " + item.MaterialName,
          }));
          _this.columnsQualityDefectReview = QualityDefectReviewMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取生产线
    async getPline() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/PLineEquipment/GetList?FactoryID=TC00"
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            plineId: item.PLineID,
            plineName: item.PLineName,
          }));
          _this.columnspline = teamMap;
          _this.columnsplinenew = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取订单信息
    async getProductionOrder() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/ProductionOrder/GetList?POrderID=" +
          _this.form.POrderID
        );
        if (res.HttpCode === "200" && res.Total == 1) {
          Toast.clear();
          _this.form.POrderID = res.Data[0].POrderID;
          _this.form.MaterialID = res.Data[0].MaterialID;
          _this.form.MaterialName = res.Data[0].MaterialName;
        } else {
          (_this.form.MaterialID = ""), (_this.form.MaterialName = "");
          Toast.fail("请将订单号输入在精准一些");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取班次信息
    async getshift(FactoryID) {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/ProductionShift/GetList?FactoryID=" +
          FactoryID
        );
        if (res.HttpCode === "200") {
          for (let index = 0; index < res.Data.length; index++) {
            if (res.Data[index].Actived == false) {
              delete res.Data[index];
            }
          }
          let shiftMap = res.Data.map((item) => ({
            pshiftname: item.PShiftName + " " + item.BeginTime,
            pShiftID: item.PShiftID,
            pShiftTime: item.ShiftLong,
          }));
          _this.columnsshift = shiftMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取班组信息
    async getteam(FactoryID) {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/Team/GetList?FactoryID=" +
          FactoryID
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            teamId: item.TeamID,
            teamName: item.TeamName,
          }));
          _this.columnsteamId = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
  },
};
</script>

<style>
body {
  background-color: white;
}

.table-title-class {
  background-color: #304156;
  color: #fff;
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.buttongroup {
  float: right;
  margin-right: 10px;
  margin-top: 10px;
  margin-bottom: 20px;
}

.container.dwo {
  display: flex;
  justify-content: center;
  align-items: center;
}

.buttonLeft {
  position: fixed;
  bottom: 8px;
  float: left;
  width: 49%;
}

.formstyle {
  margin-top: 8px;
  font-size: 15px;
  font-weight: bold;
  display: flex;
  align-items: center;
}

.radioteam {
  display: flex;
  align-items: center;
  padding-left: 13px;
  margin-top: 10px;
  margin-left: 34px;
  margin-bottom: 10px;
}

.buttonRight {
  position: fixed;
  bottom: 8px;
  float: right;
  left: 51%;
  width: 49%;
  background-color: #f22028;
  border-color: #f22028;
}

.textScroll {
  display: inline-block;
  position: fixed;
  top: 50%;
  bottom: 3rem;
  overflow: scroll;
  right: 10px;
  width: 100%;
  z-index: 1;
}

.message {
  font-size: 15px;
  margin-top: 5px;
  margin-left: -10px;
  font-weight: bold;
}

.mg5 {
  margin-right: 5px;
}

.tag_margin {
  margin: 2px 5px;
}

.card_under {
  height: 100%;
  width: 100%;
  margin: auto;
  background: #ffffff;
  border-radius: 25px;
  box-shadow: 0 0px 0px rgba(0, 0, 0, 0.3);
}

.card_icon {
  text-align: center;
  /* position: absolute; */
  height: 8rem;
  width: 80%;
  margin: 12% 10%;
  background: rgba(35, 180, 237, 1);
  border-radius: 25px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
}

.text {
  font-size: 18px;
  color: #4e4a67;
  margin: 8px auto auto 20px;
  line-height: 1.5rem;
  text-align: justify;
  font-weight: 600;
}

.text_small {
  font-size: 16px;
  color: red;
  margin: 8px auto auto 20px;
  line-height: 1.5rem;
  text-align: justify;
  font-weight: 700;
}

.text_scan {
  font-size: 16px;
  color: #4e4a67;
  margin: auto auto auto 20px;
  line-height: 1.5em;
  text-align: justify;
}

.divStyle {
  margin-left: 3px;
  margin-right: 3px;
}

/* .van-field__control{border:1px solid #ccc!important} */
</style>
